package com.msr.controller;

import com.msr.bean.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tom
 * @version V1.0
 * @Package com.msr.controller
 * @date 2025/1/15 10:18
 * @Copyright © 株式会社多言语系统研究所
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/method01")
    public String method01(Model model){
        model.addAttribute("name","tom");
        return "index";
    }

    @RequestMapping("/method02")
    public String method02(Model model, HttpSession session){ // session
        User user = new User(1001,"tom","123");
        //model.addAttribute("user",user);   request
        session.setAttribute("user",user); // session

        User user1 = new User(1001,"tom1","123");
        User user2 = new User(1002,"tom2","456");
        User user3 = new User(1003,"tom3","789");

        List<User> userList = new ArrayList<>();
        userList.add(user1);
        userList.add(user2);
        userList.add(user3);

        model.addAttribute("userList",userList);

        return "index";
    }
}
